/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.core.editpart;

import java.beans.PropertyChangeListener;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.LayoutManager;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.NodeEditPart;

import com.cea.papyrus.core.editor.ModelManager;
import com.cea.papyrus.diagraminterchange2.di2.GraphNode;

/**
 * 
 */
public class AnchorEditPart 	extends GraphNodeWithSemanticEditPart
implements NodeEditPart, Adapter,PropertyChangeListener
{
	
	/**
	 * Creates a new NodeEditPart instance.
	 * All element that can be display is a graphNode.
	 * 
	 * @param modelManager 
	 * @param graphnode 
	 * @param graphNode 	 */
	public AnchorEditPart(GraphNode graphnode,ModelManager modelManager) {
		super(graphnode,modelManager);
	}
	

	/**
	 * The model that is associated to this element is a GraphNode.
	 * 
	 * @return the GraphNode
	 */
	@Override
	public GraphNode getGraphNode() {
		return (GraphNode)getModel();
	}
	
		
	/**
	 * Returns the Figure of this, as a node type figure.
	 * The default figure is an element node : a red rectangle
	 * 
	 * @return  Figure as a NodeFigure.
	 */
	protected RectangleFigure getAnchorFigure(){
		return (RectangleFigure)createFigure() ;
	}
	
	/**
	 * 
	 */
	@Override
	protected void refreshVisuals() {
		
		Dimension size = getGraphNode().getSize();
		Point p = getGraphNode().getPosition();
		//size.height=2;
		//size.width=2;
		Rectangle r = new Rectangle(p ,size);
		RectangleFigure f = (RectangleFigure)getFigure();
		
		/*((GraphicalEditPart) getParent()).setLayoutConstraint(
				this,
				f,
				r);*/
		LayoutManager layout=((GraphicalEditPart) getParent()).getContentPane().getLayoutManager();
		/*layout.setConstraint(
				f,
				r);*/
		
	}
		
	
	/* (non-Javadoc)
	 * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
	 */
	/**
	 * 
	 * 
	 * @return 
	 */
	@Override
	protected IFigure createFigure() {
		
		IFigure figure = new RectangleFigure();
		
		return figure;
		
	}
	
}
